package main

import (
	"flag"
	"fmt"
	"os"

	"gitee.com/little_xiang_admin/go-web-api/internal/config"
	"gitee.com/little_xiang_admin/go-web-api/routers"
)

func main() {
	envName := flag.String("env", "dev", "choose environment to start app")
	user := flag.String("user", "admin", "tell me who you are")

	flag.PrintDefaults()
	flag.Parse() // Scans the arg list and sets up flags
	fmt.Println("app is start with ", *envName, " by ", *user)

	serverConfig, err := config.LoadConfig(*envName)
	if err != nil {
		fmt.Println("load config error:", err)
		os.Exit(1)
	} else {
		port := serverConfig.Server.Port
		fmt.Println("server config:", port)

		r := routers.Routers()
		r.Run(":" + port)
	}

}
